﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Resources;

namespace Mjudoku.sudokuTasks
{
    class SimpleFileTaskLoader : TaskLoader
    {

        public int[,] loadTask(int size)
        {
                Random r = new Random();
                int rnd = r.Next(1, 6);
                int[,] array = new int[0, 0];

                //zatím neufngují resources

                using (StreamReader sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mjudoku.Properties.Resources.resource.test")))
            {
                    string line;
                    bool lengthInit = false;
                    int length = 0;
                    int index = 0;
                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arrayLine = line.Split(';');
                        if (!lengthInit)
                        {
                            length = arrayLine.Length;
                            lengthInit = true;
                            array = new int[length, length];
                        }
                        else
                        {
                            if (length != arrayLine.Length)
                            {
                                MessageBox.Show("Chyba při čtení zadání.", "Chyba");
                                Environment.Exit(1);
                            }
                        }

                        for (int i = 0; i < length; i++)
                        {
                            array[index, i] = Convert.ToInt32(arrayLine[i]);
                        }
                        index++;
                        if (index == length)
                        {
                            break;
                        }
                    }
                }
                return array;                           
        }
    }
}
